var project_cofnig = {
	'service_url':'https://shopadmin.7ying.cc/zhgd20180606_service/index.php/home/index/request',
	'service_time':'https://shopadmin.7ying.cc/zhgd20180606_service/index.php/home/index/timestamp',
	'service_dec':'https://shopadmin.7ying.cc/zhgd20180606_service/index.php/home/index/timestamp_dec',
	'service_past_time':'https://shopadmin.7ying.cc/zhgd20180606_service/index.php/home/index/past_time',
	'old_time':'https://shopadmin.7ying.cc/zhgd20180606_service/index.php/home/index/old_timestamp',
	'time_dec':'https://shopadmin.7ying.cc/zhgd20180606_service/index.php/home/index/time_dec',
	
};
var _mui_dialog = {
	_message:'操作成功',
	_title:'智慧工地',
	_options:{ duration:'short'},
	_alert:function(message,title,btnValue,callback,type){
		mui.alert((message ? message : this._message ),(title ? title : this._title),btnValue,callback);
	},
	_confirm:function(message,title,btnValue,callback,type){
		mui.confirm((message ? message : this._message ),(title ? title : this._title),btnValue,callback);
	},
	_prompt:function(message,placeholder,title,btnValue,func,type){
		mui.prompt((message ? message : this._message ),placeholder,(title ? title : this._title),btnValue,func);
	},
	_toast:function(message,options){
		mui.toast((message ? message : this._message ),(options ? options : this._options ));
	},
	_closePopup:function(){
		//关闭最后一次弹出的对话框（只能关闭h5模式的对话框）
		mui.closePopup();
	},
	_closePopups:function(){
		//关闭所有对话框（只能关闭h5模式的对话框）
		mui.closePopups();
	},
	
};

//换算百分比格式
function toPercent(point,unit){
	var str = Number(point*100).toFixed(1);
	if(!unit){
		str += "%";
	}
	return str;
}

function get_token(){
	var token = plus.storage.getItem("token");
	var message = '';
	if(token == 'logout'){
		redirect();
		return false;
	}
	mui.ajax(project_cofnig.service_url,{
		data:{api:'get-tower-real-time-gather-info',token:token},
		async:false, 
		dataType:'json',
		type:'post',            
		success:function(data){
			if(data.code != 0){
				var data = {};
				data.api = 'verify';
				data.logName = plus.storage.getItem("logName");
				data.password = plus.storage.getItem("password");
				var url = 'https://shopadmin.7ying.cc/zhgd20180606_service/index.php/home/index/request';
				mui.ajax(project_cofnig.service_url,{
					data:data,
					async:false, 
					dataType:'json',
					type:'post',            
					success:function(ref){
						if(ref.code != 0){
							redirect();
							return false;
						}else{
							plus.storage.setItem('password',data.password);
							plus.storage.setItem('logName',data.logName);
							mui.each(ref.data,function(i,v){
								plus.storage.setItem(i,v);
							});
							token = ref.data.token;
						}
					}
				});
			}
		}
	});
	return token;
}

function redirect(url='',extras={},createNew=true){
	var _url = url ? url : 'login.html';
	var view = mui.openWindow({
		url:_url,
		id:_url,
		createNew:createNew,
		extras:extras,
	});  
	return false;
}

function get_ws(){
	return plus.webview.currentWebview();
}

//定时器
function get_data_setlnterval(code,time){
	if(code == undefined) return false;
	if(!time) time = 30000; 
	return setInterval(code,time);
}

function get_statusDesc_rgb(statusDesc='正常'){
	var rgb = '';
	switch(statusDesc)
		{
			case '正常':
			  rgb = '#32CD32';
			  break;
			case '违章':
			case '预警':
			case '报警':
				rgb = '#FF3030';
				break;
		}
	return rgb;
}


